package com.example.demo.core.web.core.exception;

import com.example.demo.core.web.core.model.ErrorCode;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 服务器异常 Exception
 *
 * @author airhead
 */
@Data
@EqualsAndHashCode(callSuper = true)
public final class ServerException extends RuntimeException {

  /** 全局错误码 */
  private Integer code;

  /** 错误提示 */
  private String message;

  /** 空构造方法，避免反序列化问题 */
  public ServerException() {}

  public ServerException(ErrorCode errorCode) {
    this.code = errorCode.getCode();
    this.message = errorCode.getMsg();
  }

  public ServerException(Integer code, String message) {
    this.code = code;
    this.message = message;
  }

  public Integer getCode() {
    return code;
  }

  public ServerException setCode(Integer code) {
    this.code = code;
    return this;
  }

  @Override
  public String getMessage() {
    return message;
  }

  public ServerException setMessage(String message) {
    this.message = message;
    return this;
  }
}
